package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import form.ConnectionDB;

import model.Mucdanhgia;

public class MucdanhgiaDAO {

	public static ArrayList<Mucdanhgia> select() throws ClassNotFoundException,
			SQLException {
		Connection connection = ConnectionDB.getConnection();
		ArrayList<Mucdanhgia> listMucdanhgia = new ArrayList<>();
		String sql = "select * from mucdanhgia";
		PreparedStatement ps = connection.prepareStatement(sql);
		ResultSet resultSet = ps.executeQuery();
		while (resultSet.next()) {
			int mucdanhgia_id = resultSet.getInt(1);
			String tenmucdanhgia = resultSet.getString(2);
			listMucdanhgia.add(new Mucdanhgia(mucdanhgia_id, tenmucdanhgia));

		}
		connection.close();

		return listMucdanhgia;

	}

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
//		ArrayList<Mucdanhgia> listMucdanhgia = select();
//		for (Mucdanhgia mucdanhgia : listMucdanhgia) {
//			System.out.println(mucdanhgia.toString());
//		}
	}

}
